use cipher::{
    block_padding::{Pkcs7, UnpadError},
    BlockDecryptMut, KeyIvInit,
};

#[allow(unused)]
pub fn dec_aes_128<'a, 'b, 'c>(
    data: &'a mut [u8],
    key: &'b [u8],
    iv: &'c [u8],
) -> anyhow::Result<&'a [u8], UnpadError> {
    type Aes128CbcDec = cbc::Decryptor<aes::Aes128>;
    Ok(Aes128CbcDec::new(key.into(), iv.into()).decrypt_padded_mut::<Pkcs7>(data)?)
}

#[cfg(test)]
mod tests {

    #[test]
    fn test_dec() -> anyhow::Result<()> {
        // let mut file = File::open("./317KIMIM.ts")?;
        // let mut data = Vec::new();
        // file.read_to_end(&mut data).unwrap();

        // let key = "b155513acaeb8e8a".as_bytes();
        // let iv = key;

        // type Aes128CbcDec = cbc::Decryptor<aes::Aes128>;
        // let res = Aes128CbcDec::new(key.into(), iv.into())
        //     .decrypt_padded_mut::<Pkcs7>(&mut data)
        //     .unwrap();
        // let mut out = File::create_new("./out.ts")?;
        // out.write_all(res)?;

        Ok(())
    }
}
